package main

import "fmt"

type tree struct {
	data string
	left *tree
	right *tree
}

//先序遍历
func preTree(tree2 *tree) {

	if tree2 != nil {
		fmt.Println(tree2.data)
		if nil != tree2.left {
			preTree(tree2.left)
		}
		if nil != tree2.right {
			preTree(tree2.right)
		}
	}
}

//中序遍历
func innerTree(tree2 *tree) {
	if tree2 != nil {
		if tree2.left != nil {
			innerTree(tree2.left)
		}
		fmt.Println(tree2.data)
		if tree2.right != nil {
			innerTree(tree2.right)
		}
	}
}

//后续遍历
func afterTree(tree2 *tree) {
	if tree2 != nil {
		if tree2.left != nil {
			afterTree(tree2.left)
		}
		if tree2.right != nil {
			afterTree(tree2.right)
		}
		fmt.Println(tree2.data)
	}
}

func main() {
	var a = tree{data: "A"}
	var b = tree{data: "B"}
	var c = tree{data: "C"}
	var d = tree{data: "D"}
	var e = tree{data: "E"}

	a.left = &b
	a.right = &c
	c.left = &d
	d.right = &e


	preTree(&a)
	fmt.Println("--------")
	innerTree(&a)
	fmt.Println("--------")
	afterTree(&a)
}